package com.action;

import java.util.List;

import com.model.Menu;
import com.model.Role;
import com.service.MenuService;
import com.service.MenuServiceImpl;
import com.service.RoleService;
import com.service.RoleServiceImpl;
/**   
 *   
 * @author zhanghusong   
 */
public class RoleAction extends DefaultAction {

	private static final long serialVersionUID = 1L;
	RoleService service;
	List<Role> list;
	Role model;
	List<Menu> menuList;
	MenuService mservice;
	String []menuroleid;
	
	public RoleAction()
	{
		service = new RoleServiceImpl();
		mservice = new MenuServiceImpl();
	}
	String type="";
	String msg="";
	public String list()
	{ 
		list = service.getRole();
		menuList = mservice.getMenu();
		return SUCCESS;
	}
	public String save()
	{ 
		String menustr="";
		if(type.equals("add"))
		{ 
			if(menuroleid!=null && menuroleid.length>0)
			{
				for(String str:menuroleid)
				{
					menustr=menustr+str+"_";
				}
			}
			model.setMenuValue(menustr);
			model.setCreateUser(getAdminLoginName());
			if(service.saveRole(model))
				msg = "添加成功";
			else
				msg = "添加失败！！请重新添加！！";
		}
		else if(type.equals("update"))
		{
			if(menuroleid!=null && menuroleid.length>0)
			{
				for(String str:menuroleid)
				{
					menustr=menustr+str+"_";
				}
			}
			model.setMenuValue(menustr);
			if(service.updateRole(model))
				msg = "更新成功！！";
			else
				msg = "更新失败！！请重新更新！！";
			type = "upd";
		}
		else if(type.equals("del"))
		{
			if(service.deleteRole(model))
				msg = "删除成功！！";
			else
				msg = "删除失败！！请重新删除！！";
		}
		
		//list = service.getRole();
		menuList = mservice.getMenu();
		return SUCCESS;
	}
	public String show()
	{ 
//		String menustr="";
//		if(type.equals("add"))
//		{ 
//			if(menuroleid!=null && menuroleid.length>0)
//			{
//				for(String str:menuroleid)
//				{
//					menustr=menustr+str+"_";
//				}
//			}
//			model.setMenuValue(menustr);
//			model.setCreateUser(getAdminLoginName());
//			if(service.saveRole(model))
//				msg = "添加成功";
//			else
//				msg = "添加失败！！请重新添加！！";
//		}
//		else if(type.equals("update"))
//		{
//			if(menuroleid!=null && menuroleid.length>0)
//			{
//				for(String str:menuroleid)
//				{
//					menustr=menustr+str+"_";
//				}
//			}
//			model.setMenuValue(menustr);
//			if(service.updateRole(model))
//				msg = "更新成功！！";
//			else
//				msg = "更新失败！！请重新更新！！";
//			type = "upd";
//		}
//		else if(type.equals("del"))
//		{
//			if(service.deleteRole(model))
//				msg = "删除成功！！";
//			else
//				msg = "删除失败！！请重新删除！！";
//		}
//		else 
		if(type.equals("upd"))
		{
			model = service.getRoleById(model);
		}
		//list = service.getRole();
		menuList = mservice.getMenu();
		return SUCCESS;
	}
	public List<Role> getList() {
		return list;
	}
	public void setList(List<Role> list) {
		this.list = list;
	}
	public Role getModel() {
		return model;
	}
	public void setModel(Role model) {
		this.model = model;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public List<Menu> getMenuList() {
		return menuList;
	}
	public void setMenuList(List<Menu> menuList) {
		this.menuList = menuList;
	}
	public String[] getMenuroleid() {
		return menuroleid;
	}
	public void setMenuroleid(String[] menuroleid) {
		this.menuroleid = menuroleid;
	}
	
	
}
